package com.kk.xhr.admin.controller;

import com.kk.xhr.admin.biz.IStatisticsService;
import com.kk.xhr.admin.controller.vo.SignDayVO;
import com.kk.xhr.web.vo.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Executor;

/**
 * 数据统计管理器
 *
 * @author kkmystery
 * @version 1.0 2021/3/29
 * @since 1.0.0
 */
@RestController
@RequestMapping("/statistics")
@Api(value = "数据统计管理", tags = "数据统计管理")
@RequiredArgsConstructor
public class StatisticsController {
    private final Executor adminControllerBizExecutor;
    private final IStatisticsService statisticsService;

    @ApiOperation(value = "查询上一周的考勤记录")
    @RequestMapping("/signOfWeek")
    @RequiresRoles({"admin"})
    public CompletionStage<ApiResult<List<Long>>> queryWeekSignRecord(){
        return CompletableFuture.supplyAsync(()->ApiResult.success(statisticsService.queryWeekSignRecord()), adminControllerBizExecutor);
    }

    @ApiOperation(value = "当天签到情况")
    @RequestMapping("/signOfDay")
    @RequiresRoles({"admin"})
    public CompletionStage<ApiResult<SignDayVO>> queryDaySignRecord(){
        return CompletableFuture.supplyAsync(()->ApiResult.success(statisticsService.queryDaySignRecord()), adminControllerBizExecutor);
    }
}
